<div class="page-header">
    <h3><?php echo lang('events_tab_admin'); ?></h3>
</div>

<div class="tabbable">
    <ul class="nav nav-pills">
        <?php
        $pill_active = key($classes);
        foreach(array_keys($classes) as $class)
            echo '<li class="'.(($class === $pill_active) ? 'active' : '').'"><a href="#'.$class.'" data-toggle="tab">'.$class.'</a></li>';
        ?>
    </ul>
    <div class="tab-content">
        <?php
        foreach($classes as $class => $events_by_class) {
            echo '<div class="tab-pane '.(($class === $pill_active) ? 'active' : '').'" id="'.$class.'">';
            if(empty($events_by_class)):
            ?>

            <p class="events-by-class alert"><?php echo lang('events_by_class_none'); ?></p>

            <?php else: ?>

            <table class="events-by-class table table-condensed well">
                <tr>
                    <th><?php echo lang('event_publish_date'); ?></th>
                    <th><?php echo lang('event_title'); ?></th>
                    <th><?php echo nbs(); ?></th>
                </tr>
                <?php foreach($events_by_class as $event_id => $event): ?>
                <tr>
                    <td class="none"><?php echo $event_id; ?></td>
                    <td><?php echo $event['published'] ? $event['publish_date'].' '.$event['publish_time'] : ''; ?></td>
                    <td><?php echo $event['title']; ?></td>
                    <td>
                        <div class="btn-group">
                            <?php
                            if($event['published'])
                                echo anchor('events/mask/'.$class.'/'.$event_id, lang('mask'), 'class="btn event-mask"');
                            else
                                echo anchor('events/show/'.$class.'/'.$event_id, lang('show'), 'class="btn event-show"');
                            echo anchor('events/unlink/'.$class.'/'.$event_id, lang('unlink'), 'class="btn event-unlink"');
                            ?>
                        </div>
                    </td>
                </tr>
                <?php endforeach; ?>
            </table>

            <?php
            endif;
            echo '</div>';
        }
        ?>
    </div>
</div>

<hr />

<?php if(empty($events_by_user)): ?>

<p class="alert"><?php echo lang('events_by_user_none').' '.anchor('events/edit', lang('event_create')); ?></p>

<?php else: ?>

<table id="events_by_user" class="table table-condensed well">
    <tr>
        <th><?php echo lang('event_creation_date'); ?></th>
        <th><?php echo lang('event_last_update'); ?></th>
        <th><?php echo lang('event_title'); ?></th>
        <th><?php echo nbs(); ?></th>
        <th><?php echo nbs(); ?></th>
    </tr>
    <?php foreach($events_by_user as $event_id => $event): ?>
    <tr>
        <td class="none"><?php echo $event_id; ?></td>
        <td><?php echo $event['creation_date'].' '.$event['creation_time']; ?></td>
        <td><?php echo $event['updated'] ? $event['last_update_date'].' '.$event['last_update_time'] : ''; ?></td>
        <td><?php echo anchor('events/view/'.$event_id, $event['title']); ?></td>
        <td>
            <div class="btn-group">
                <?php echo anchor('#', lang('link').' <span class="caret">'.nbs().'</span>', 'class="btn dropdown-toggle" data-toggle="dropdown"'); ?>
                <ul class="dropdown-menu">
                    <?php
                    foreach($classes as $class => $events_by_class)
                        if(!in_array($event_id, array_keys($events_by_class)))
                            echo '<li>'.anchor('events/link/'.$class.'/'.$event_id, $class, 'class="event-link"').'</li>';
                    ?>
                </ul>
            </div>
        </td>
        <td>
            <div class="btn-group">
                <?php
                echo
                anchor('events/edit/'.$event_id, lang('edit'), 'class="btn event-edit"').
                anchor('events/delete/'.$event_id, lang('delete'), 'class="btn btn-danger event-delete"');
                ?>
            </div>
        </td>
    </tr>
    <?php endforeach; ?>
</table>

<p class="event-create"><?php echo anchor('events/edit', lang('event_create')); ?></p>

<?php endif; ?>